<?php

/**
 * Created by PhpStorm.
 * User: 72925
 * Date: 2018/11/23
 * Time: 9:26
 * order: 登陆授权相关操作
 */


namespace app\index\controller;

use think\Controller;
use app\index\model\User;
use think\Cache;
use lib\Safety;

class Login extends Controller
{
	public function login()
	{
		// ->where(['password'=>$password])
		$mobile = input('mobile');
		$password = MD5(input('password'));
        $User = new User;
        $istrue = User::where(['mobile'=>$mobile])->find(); 
        if (!$istrue) {
            $dat = array('code'=>402,'msg'=>'此用户未注册');
            echo json_encode($dat,JSON_FORCE_OBJECT);
        }    

        if ($password !== User::where(['mobile'=>$mobile])->value('password')) {
            $dat = array('code'=>401,'msg'=>'用户名或密码错误');
            echo json_encode($dat,JSON_FORCE_OBJECT);
        } else if ($info = $istrue->visible(['id','mobile','grade'])->toArray()) {
            $sevenday = date('Y-m-d:H:i:s',strtotime("+7 day"));
            $update = User::where('id',$info['id'])->update(['updated_at'=>$sevenday]);
            $dat = array('code'=>200,'msg'=>'登录成功','needinfo'=>$info);
            echo json_encode($dat,JSON_FORCE_OBJECT);
        }
        
    }
}